﻿// Copyright (c) Vitaly Kamiansky. All rights reserved. 
// See License.txt in the project root.

using System;
using System.Windows.Forms;

namespace Property.Windows.Forms
{
    /// <summary>
    /// Contains words that can come immediately after the opening
    /// of a property description. 
    /// </summary>
    public static class ReloadableExtensionsReactiveWindowsForms
    {
        /// <summary>
        /// <para>... asynchronously ...</para>
        /// <para>New values will be loaded on a new thread and applied on the thread of the specified control.</para>
        /// </summary>
        /// <param name="control">Tell me which control I can use to deduce the UI thread.</param>
        /// <param name="testMode">Tell me if I have to ignore this word.</param>
        public static ISequenceConveyor<T> Async<T>(this Reloadable<T> source, Control control, bool testMode = false)
        {
            return source.Reactive().Async(control, testMode);
        }

        /// <summary>
        /// <para>... synchronously if the call passes through the throttle (when) ...</para>
        /// <para>( ! ) Don't forget to dispose of what you create with this word.</para>
        /// </summary>
        /// <param name="dueTime">Tell me how long I should
        /// wait for another call before letting this one pass.</param>
        /// <param name="control">Give me a control I can use to deduce the UI thread.</param>
        /// <param name="testMode">Tell me if I have to ignore this word.</param>
        public static IReloaderPrototype<T> Throttle<T>(this Reloadable<T> source, TimeSpan dueTime, Control control, bool testMode = false)
        {
            return source.Each().Throttle(dueTime, control, testMode);
        }
    }
}
